<template>
  <div class="">
    <el-card>
      <el-table style="width: 100%" :data="roleList" border>
        <el-table-column
          type="index"
          :label="$t('msg.role.index')"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="title"
          :label="$t('msg.role.name')"
        ></el-table-column>
        <el-table-column
          prop="describe"
          :label="$t('msg.role.desc')"
        ></el-table-column>
        <el-table-column
          width="200"
          :label="$t('msg.role.action')"
          #default="{ row }"
          ><el-button
            type="primary"
            size="small"
            v-permission="['distributePermission']"
            @click="onDistributePermissionClick(row)"
            >{{ $t('msg.role.assignPermissions') }}</el-button
          ></el-table-column
        >
      </el-table>
    </el-card>
    <DistributePermission
      v-model="distributePermissionVisible"
      :roleId="selectRoleId"
    ></DistributePermission>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getRoleList } from '@/api/role'
import { watchSwitchLang } from '@/utils/i18n'
import DistributePermission from './components/DistributePermission.vue'

// 获取角色列表
const roleList = ref([])
const getRoleListData = async () => {
  roleList.value = await getRoleList()
  console.log(roleList.value)
}
getRoleListData()
watchSwitchLang(getRoleListData)

// 分配权限
const distributePermissionVisible = ref(false)
const selectRoleId = ref('')
const onDistributePermissionClick = (row) => {
  distributePermissionVisible.value = true
  console.log(row)
  selectRoleId.value = row.id
}
</script>

<style lang="scss" scoped></style>
